package com.tianyuan.dplrf.wxapi;

import android.content.Intent;
import android.graphics.Color;

import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.tianyuan.dplrf.app.AppActivity;
import com.tianyuan.dplrf.other.Constant;

/**
 *    desc   : 微信登录回调（请注意这个 Activity 放置的包名要和当前项目的包名保持一致，否则将不能正常回调）
 */
public final class WXEntryActivity extends AppActivity implements IWXAPIEventHandler {
    private IWXAPI api;
    @Override
    protected int getLayoutId() {
        return 0;
    }

    @Override
    protected void initView() {
        getWindow().setStatusBarColor(Color.parseColor("#000000"));
        api = WXAPIFactory.createWXAPI(getApplicationContext(), Constant.WXAPP_ID, true);
        api.handleIntent(getIntent(), this);


    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(getIntent(), this);
        WXEntryActivity.this.finish();
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onReq(BaseReq baseReq) {

    }

    @Override
    public void onResp(BaseResp resp) {
        if(resp.getType() == ConstantsAPI.COMMAND_SENDAUTH){
            //微信登录
        }else if(resp.getType() == ConstantsAPI.COMMAND_SENDMESSAGE_TO_WX){
            //微信分享
            String result = "";
            switch (resp.errCode){
                case BaseResp.ErrCode.ERR_OK:
                    result = "分享成功";
                    break;
                default:
                    result = "分享失败";
                    break;

            }
            toast(result);
        }
        WXEntryActivity.this.finish();


    }
}